package com.linwen;

import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 */
public class App {
    static List<String> result = new ArrayList<>();
    public static void main(String[] args) {
        int n = 3;
        function(n,n,result,"");
        for (String s : result) {
            System.out.println(s);
        }
    }

    public static void function(int left, int right, List result,String str){
        if(left==right&&left==0){// 用完了
            result.add(str);
            return;
        }
        if(left>0){// 左边还能加
            function(left-1,right,result,str+"(");
        }
        if(right>left){
            function(left,right-1,result,str+")");
        }
    }

}
